/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jobs.model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Paul Tamayo
 */
@Entity
@Table(name = "experience")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Experience.findAll", query = "SELECT e FROM Experience e"),
    @NamedQuery(name = "Experience.findById", query = "SELECT e FROM Experience e WHERE e.id = :id"),
    @NamedQuery(name = "Experience.findByDescription", query = "SELECT e FROM Experience e WHERE e.description = :description")})
public class Experience implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Size(max = 200)
    @Column(name = "description")
    private String description;
    @JoinTable(name = "experience_year", joinColumns = {
        @JoinColumn(name = "experience_id", referencedColumnName = "id")}, inverseJoinColumns = {
        @JoinColumn(name = "year_id", referencedColumnName = "id")})
    @ManyToMany
    private Collection<Year> yearCollection;
    @JoinTable(name = "experience_knowledge_area", joinColumns = {
        @JoinColumn(name = "experience_id", referencedColumnName = "id")}, inverseJoinColumns = {
        @JoinColumn(name = "knowledge_area_id", referencedColumnName = "id")})
    @ManyToMany
    private Collection<KnowledgeArea> knowledgeAreaCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "experienceId")
    private Collection<Jobs> jobsCollection;
    @JoinColumn(name = "especificity_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Especificity especificityId;

    public Experience() {
    }

    public Experience(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlTransient
    public Collection<Year> getYearCollection() {
        return yearCollection;
    }

    public void setYearCollection(Collection<Year> yearCollection) {
        this.yearCollection = yearCollection;
    }

    @XmlTransient
    public Collection<KnowledgeArea> getKnowledgeAreaCollection() {
        return knowledgeAreaCollection;
    }

    public void setKnowledgeAreaCollection(Collection<KnowledgeArea> knowledgeAreaCollection) {
        this.knowledgeAreaCollection = knowledgeAreaCollection;
    }

    @XmlTransient
    public Collection<Jobs> getJobsCollection() {
        return jobsCollection;
    }

    public void setJobsCollection(Collection<Jobs> jobsCollection) {
        this.jobsCollection = jobsCollection;
    }

    public Especificity getEspecificityId() {
        return especificityId;
    }

    public void setEspecificityId(Especificity especificityId) {
        this.especificityId = especificityId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Experience)) {
            return false;
        }
        Experience other = (Experience) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jobs.jpa.Experience[ id=" + id + " ]";
    }
    
}
